

import org.junit.Test
/**
 * Created with IntelliJ IDEA.
 * User: vuntermann
 * Date: 20/05/13
 * Time: 18:34
 * To change this template use File | Settings | File Templates.
 */
class CashRegisterTest {

    @Test
    void calculateTotalForASingleProductWithoutPromotion(){
        def priceList = ['A': 50, 'B': 30, 'C':20, 'D':15]
        def promotions = ['B': new Promotion(2, 20)]

        def cashRegister = new CashRegister(priceList, promotions)

        Ticket ticket = cashRegister.calculateTotalFor(['A'])

        assert  priceList['A'] == ticket.total
    }

    @Test
    void calculateTotalForProductWithPromotion(){
        def priceList = ['A': 50, 'B': 30, 'C':20, 'D':15]
        def promotions = ['B': new Promotion(2, 20)]

        def cashRegister = new CashRegister(priceList, promotions)

        Ticket ticket = cashRegister.calculateTotalFor(['B', 'A', 'B'])

        assert (20 + 50) ==  ticket.total
    }

}
